
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module config-manager
* @author: Hjava
* @description: 用户信息管理模块
* @since: 2018-07-23 12:56:26
*/
var event_emitter_1 = __webpack_require__(/*! _Eutils/event-emitter */ "./src/extra/utils/event-emitter.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var promise_1 = __webpack_require__(/*! _util/promise */ "./src/core/utils/promise.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/extra/utils/log.ts");
var DAO;
if (false) {}
else {
    DAO = __webpack_require__(/*! ../dao */ "./src/extra/dao/index.ts").default;
}
var ConfigManager = /** @class */ (function () {
    function ConfigManager() {
        this.mtdx = {};
        this._config = {};
    }
    ConfigManager.prototype.init = function (mtdx) {
        var _this = this;
        log_1.default.log('ConfigManager::init');
        this.mtdx = mtdx;
        var CONNECTING = constant_1.LOGIN_EVENT.CONNECTING, CONNECTED = constant_1.LOGIN_EVENT.CONNECTED, AUTHENTICATING = constant_1.LOGIN_EVENT.AUTHENTICATING, AUTH_SUCCESS = constant_1.LOGIN_EVENT.AUTH_SUCCESS, AUTH_FAIL = constant_1.LOGIN_EVENT.AUTH_FAIL, DISCONNECT = constant_1.LOGIN_EVENT.DISCONNECT;
        this.mtdx.on(AUTH_SUCCESS, function (uid, xsid, appId, altoken) {
            if (uid === void 0) { uid = ''; }
            if (xsid === void 0) { xsid = ''; }
            if (appId === void 0) { appId = ''; }
            if (altoken === void 0) { altoken = ''; }
            var config = {
                uid: uid,
                xsid: xsid,
                appId: appId,
                altoken: altoken
            };
            _this._config = __assign(__assign({}, _this._config), config);
            DAO.initDB(uid);
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.AUTH_SUCCESS, config);
        });
        this.mtdx.on(AUTH_FAIL, function (rescode) {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.AUTH_FAIL, { rescode: rescode });
        });
        this.mtdx.on('KickOff', function () {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.KICK_OFF);
        });
        this.mtdx.on('KickOffWithSameDeviceId', function () {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.KICK_OFF);
        });
        this.mtdx.on('Logout', function () {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.LOGOUT);
        });
        this.mtdx.on(CONNECTING, function () {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.CONNECTING);
        });
        this.mtdx.on(CONNECTED, function () {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.CONNECTED);
        });
        this.mtdx.on(AUTHENTICATING, function () {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.AUTHENTICATING);
        });
        this.mtdx.on(DISCONNECT, function (status) {
            event_emitter_1.default.emit(event_emitter_1.EVENT_NAME.DISCONNECT);
        });
    };
    ConfigManager.prototype.setInitOpts = function (opts) {
        opts.dt = opts.dt || opts.deviceType;
        this._config = opts;
    };
    ConfigManager.prototype.getConfig = function () {
        return this._config;
    };
    ConfigManager.prototype.loginWithPassport = function (_a) {
        var _b = _a.uid, uid = _b === void 0 ? '' : _b, _c = _a.token, token = _c === void 0 ? '' : _c, _d = _a.supportMultiDevices, supportMultiDevices = _d === void 0 ? false : _d, _e = _a.pushToken, pushToken = _e === void 0 ? '' : _e;
        this.mtdx.login(uid, token, supportMultiDevices, pushToken);
    };
    ConfigManager.prototype.loginWithUid = function (_a) {
        var _b = _a.uid, uid = _b === void 0 ? '' : _b, _c = _a.token, token = _c === void 0 ? '' : _c, _d = _a.supportMultiDevices, supportMultiDevices = _d === void 0 ? false : _d, _e = _a.pushToken, pushToken = _e === void 0 ? '' : _e;
        this.mtdx.loginWithUidAndToken(uid, token, supportMultiDevices, pushToken);
    };
    ConfigManager.prototype.loginWithVisitor = function (_a) {
        var _b = _a.uid, uid = _b === void 0 ? '' : _b, _c = _a.token, token = _c === void 0 ? '' : _c;
        this.mtdx.loginWithVisitor(uid, token);
    };
    ConfigManager.prototype.getVisitorInfoAndLogin = function () {
        this.mtdx.getVisitorInfoAndLogin();
    };
    ConfigManager.prototype.logout = function () {
        this.mtdx.logout();
    };
    ConfigManager.prototype.reconnect = function () {
        this.mtdx.reconnect();
    };
    ConfigManager.prototype.setPushToken = function (_a) {
        var _this = this;
        var _b = _a.uid, uid = _b === void 0 ? '' : _b, _c = _a.appId, appId = _c === void 0 ? 0 : _c, _d = _a.deviceModel, deviceModel = _d === void 0 ? '' : _d, _e = _a.pushToken, pushToken = _e === void 0 ? '' : _e;
        return new promise_1.default(function (resolve, reject) {
            var dataObject = {
                u: uid,
                ai: appId,
                dm: deviceModel,
                tk: pushToken
            };
            log_1.default.info('ConfigManager::setPushToken info:' + JSON.stringify(dataObject));
            _this.mtdx.HTTP.Common.setPushToken({
                data: dataObject,
                success: function (res) {
                    if (res.rescode === 0) {
                        resolve();
                    }
                    else {
                        reject(res);
                    }
                },
                fail: function (e) {
                    log_1.default.info('ConfigManager::setPushToken fail info:' + e);
                    reject(e);
                }
            });
        });
    };
    ConfigManager.prototype.deletePushToken = function (_a) {
        var _this = this;
        var _b = _a.uid, uid = _b === void 0 ? '' : _b, _c = _a.appId, appId = _c === void 0 ? 0 : _c;
        return new promise_1.default(function (resolve, reject) {
            var dataObject = {
                u: uid,
                ai: appId
            };
            log_1.default.info('ConfigManager::deletePushToken info:' + JSON.stringify(dataObject));
            _this.mtdx.HTTP.Common.deletePushToken({
                data: dataObject,
                success: function (res) {
                    if (res.rescode === 0) {
                        resolve();
                    }
                    else {
                        reject(res);
                    }
                },
                fail: function (e) {
                    log_1.default.info('ConfigManager::deletePushToken fail info:' + e);
                    reject(e);
                }
            });
        });
    };
    ConfigManager.prototype.setSwimlane = function (swimlane) {
        this.mtdx.setSwimlane(swimlane);
    };
    return ConfigManager;
}());
exports.default = new ConfigManager();


//# sourceURL=webpack://MTDX/./src/extra/managers/config-manager.ts?